﻿<Page x:Class="vsarFlightPlan.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converters="using:vsarFlightPlan.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:vsarFlightPlan" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="page" mc:Ignorable="d">
    <Page.Resources>
        <converters:DateTimeToDateTimeOffsetConverter x:Key="DateTimeToDateTimeOffset" />
        <converters:EmptyStringToVisibilityConverter x:Key="ShowStringsWithValues" />
        <converters:EmptyStringToVisibilityConverter x:Key="ShowEmptyStrings" InvertResult="True" />
        <converters:StatusToBrush x:Key="StatusToBrushConverter" />
        <converters:StringFormatConverter x:Key="StringFormatConverter" />
        <converters:StatusToIcon x:Key="StatusToIcon" />
        <converters:BooltoVisibilityConverter x:Key="BooltoVisibility" />
        <converters:BooltoVisibilityConverter x:Key="InvertedBooltoVisibility" InvertResult="True" />
        <converters:DateTimeOffsetPrettifier x:Key="DateTimeOffsetPrettifier" />
        <converters:DateTimePrettifier x:Key="DateTimePrettifier" />

        <DataTemplate x:Key="DetailedItemDataTemplate">
            <Button Height="50" Margin="0" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" BorderThickness="0" Padding="0" Style="{StaticResource HiddenButtonStyle}">
                <Button.Flyout>
                    <Flyout Closed="Flyout_Closed" Opening="Flyout_Opening">
                        <Flyout.FlyoutPresenterStyle>
                            <Style TargetType="FlyoutPresenter">
                                <Setter Property="MaxWidth" Value="1000" />
                                <Setter Property="Height" Value="465" />
                                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Visible" />
                                <Setter Property="Background" Value="Black" />
                                <Setter Property="Foreground" Value="White" />
                            </Style>
                        </Flyout.FlyoutPresenterStyle>
                        <Grid Height="465" DataContext="{Binding}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="60" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                                <RowDefinition Height="45" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Row="0" Margin="0,0,0,12" FontSize="36" FontWeight="Light" Text="project meta data editor" />
                            <TextBlock Grid.Row="1" Grid.Column="0" Margin="0,0,12,12" Style="{StaticResource BodyTextBlockStyle}" Text="Status" />
                            <ComboBox Grid.Row="1" Grid.Column="1" Margin="0,0,0,12" ItemsSource="{Binding DataContext.Statuses, ElementName=page}" SelectedItem="{Binding StatusString, Mode=TwoWay}" />
                            <TextBlock Grid.Row="2" Grid.Column="0" Margin="0,0,12,12" Style="{StaticResource BodyTextBlockStyle}" Text="Scheduled" />
                            <DatePicker Grid.Row="2" Grid.Column="1" Margin="0,0,0,12" Date="{Binding Scheduled, Mode=TwoWay}" />
                            <TextBlock Grid.Row="3" Grid.Column="0" Margin="0,0,12,12" Style="{StaticResource BodyTextBlockStyle}" Text="Scheduled Status" />
                            <TextBox Grid.Row="3" Grid.Column="1" Margin="0,0,0,12" Text="{Binding ScheduledStatus, Mode=TwoWay}" />
                            <TextBlock Grid.Row="4" Grid.Column="0" Margin="0,0,12,12" FontFamily="Global User Interface" Style="{StaticResource BodyTextBlockStyle}" Text="Date Landed" />
                            <DatePicker Grid.Row="4" Grid.Column="1" Margin="0,0,0,12" Date="{Binding DateLandedProxy, Mode=TwoWay, Converter={StaticResource DateTimeToDateTimeOffset}}" />
                            <TextBlock Grid.Row="5" Grid.Column="0" Margin="0,0,12,12" Style="{StaticResource BodyTextBlockStyle}" Text="Version" />
                            <TextBox Grid.Row="5" Grid.Column="1" Margin="0,0,0,12" Text="{Binding Version, Mode=TwoWay}" />
                            <TextBlock Grid.Row="6" Grid.Column="0" Margin="0,0,12,12" Style="{StaticResource BodyTextBlockStyle}" Text="Project Owner" />
                            <TextBox Grid.Row="6" Grid.Column="1" Margin="0,0,0,12" Text="{Binding ProductOwner, Mode=TwoWay}" />
                            <TextBlock Grid.Row="7" Grid.Column="0" Margin="0,0,12,12" Style="{StaticResource BodyTextBlockStyle}" Text="Project Lead" />
                            <TextBox Grid.Row="7" Grid.Column="1" Margin="0,0,0,12" Text="{Binding ProjectLead, Mode=TwoWay}" />
                            <TextBlock Grid.Row="8" Grid.Column="0" Margin="0,0,12,12" Style="{StaticResource BodyTextBlockStyle}" Text="Scrum Master" />
                            <TextBox Grid.Row="8" Grid.Column="1" Margin="0,0,0,12" Text="{Binding RuckMaster, Mode=TwoWay}" />
                            <StackPanel Grid.Row="9" Grid.Column="0" HorizontalAlignment="Left" Orientation="Horizontal">
                                <Button Command="{Binding DataContext.ToggleHideStatus, ElementName=page}" CommandParameter="{Binding}" Content="Hide this item" Visibility="{Binding Hidden, Converter={StaticResource InvertedBooltoVisibility}}" />
                                <Button Command="{Binding DataContext.ToggleHideStatus, ElementName=page}" CommandParameter="{Binding}" Content="Unhide this item" Visibility="{Binding Hidden, Converter={StaticResource BooltoVisibility}}" />
                                <Button Command="{Binding ViewOnline}" Content="View on Visual Studio Online" />
                            </StackPanel>
                            <StackPanel Grid.Row="9" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
                                <Button Command="{Binding DataContext.UpdateMetadata, ElementName=page}" CommandParameter="{Binding}" Content="save" Tapped="Button_Tapped" />
                            </StackPanel>
                        </Grid>
                    </Flyout>
                </Button.Flyout>
                <Grid Height="45" Margin="0" HorizontalAlignment="Stretch" Background="{Binding Status, Converter={StaticResource StatusToBrushConverter}}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="2*" />
                        <ColumnDefinition Width="13*" />
                        <ColumnDefinition Width="3*" />
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="4*" />
                        <ColumnDefinition Width="4*" />
                        <ColumnDefinition Width="4*" />
                    </Grid.ColumnDefinitions>
                    <ContentControl Grid.Column="0" Margin="0,5" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{Binding Status, Converter={StaticResource StatusToIcon}}" d:MinWidth="50" />
                    <TextBlock Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="24" FontWeight="Light" Text="{Binding Title, FallbackValue='Mega Man'}" TextTrimming="CharacterEllipsis" d:MinWidth="296" />
                    <Grid Grid.Column="2" VerticalAlignment="Center" d:MinWidth="100">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="18" FontWeight="Light" Text="{Binding Scheduled, Converter={StaticResource DateTimeOffsetPrettifier}}" TextTrimming="CharacterEllipsis" />
                        <TextBlock Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="14" FontWeight="Light" Text="{Binding ScheduledStatus, FallbackValue=flying}" TextTrimming="CharacterEllipsis" />
                    </Grid>
                    <TextBlock Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontWeight="Light" Text="{Binding Version, FallbackValue=1}" TextWrapping="WrapWholeWords" d:MinWidth="200" />
                    <TextBlock Grid.Column="4" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontWeight="Light" Text="{Binding ProductOwner, FallbackValue='John Doe'}" TextWrapping="WrapWholeWords" d:MinWidth="200" />
                    <TextBlock Grid.Column="5" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontWeight="Light" Text="{Binding ProjectLead, FallbackValue='John Doe'}" TextWrapping="WrapWholeWords" d:MinWidth="200" />
                    <TextBlock Grid.Column="6" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontWeight="Light" Text="{Binding RuckMaster, FallbackValue='John Doe'}" TextWrapping="WrapWholeWords" />
                </Grid>
            </Button>
        </DataTemplate>
    </Page.Resources>

    <Grid Background="{StaticResource Background}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="100" />
                <RowDefinition Height="40" />
                <RowDefinition Height="10" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="120" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="55" />
                </Grid.ColumnDefinitions>
                <ContentControl Grid.Column="0" Margin="20" Style="{StaticResource IconPlane}" />
                <TextBlock Grid.Column="1" VerticalAlignment="Center" Foreground="{StaticResource PrimaryColourBrush}" Style="{StaticResource HeaderTextBlockStyle}" TextWrapping="NoWrap">FLIGHT PLAN: STATUS BOARD</TextBlock>
                <TextBlock Grid.Column="2" VerticalAlignment="Center" Foreground="{StaticResource PrimaryColourBrush}" Style="{StaticResource SubheaderTextBlockStyle}" TextWrapping="NoWrap">
                    <Run Foreground="#FF6C6C6C">Powered by</Run>
                    TFS Backlog
                </TextBlock>
            </Grid>
            <ProgressBar Grid.Row="1" Height="20" Foreground="{StaticResource PrimaryColourBrush}" IsEnabled="True" IsIndeterminate="True" Visibility="{Binding Loading, Converter={StaticResource BooltoVisibility}}" />
            <TextBlock Grid.Row="1" Margin="30,0,0,0" VerticalAlignment="Center" FontSize="20">
                <Run xml:space="preserve">Project Status @</Run><Run Text="{Binding LastUpdated, Converter={StaticResource DateTimePrettifier}}" />
            </TextBlock>
            <SearchBox x:Name="searchBox" Grid.Row="1" Width="300" Margin="0,0,50,0" HorizontalAlignment="Right" FocusOnKeyboardInput="True" PlaceholderText="just type to start searching" QueryText="{Binding Search, Mode=TwoWay}" SearchHistoryEnabled="False" />

            <ListView Grid.Row="3" Grid.Column="1" Margin="15,0,0,0" Background="{x:Null}" Foreground="White" ItemContainerStyle="{StaticResource FullWidthListViewItemStyle}" ItemTemplate="{StaticResource DetailedItemDataTemplate}" ItemsSource="{Binding DetailedItems}" SelectionMode="None">
                <ListView.Header>
                    <Grid Height="30" HorizontalAlignment="Stretch" Background="Transparent">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*" />
                            <ColumnDefinition Width="13*" />
                            <ColumnDefinition Width="3*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="4*" />
                            <ColumnDefinition Width="4*" />
                            <ColumnDefinition Width="4*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Style="{StaticResource TitleTextBlockStyle}" Text="Status" />
                        <TextBlock Grid.Column="1" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Style="{StaticResource TitleTextBlockStyle}" Text="Title" />
                        <TextBlock Grid.Column="2" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Style="{StaticResource TitleTextBlockStyle}" Text="Scheduled" />
                        <TextBlock Grid.Column="3" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Style="{StaticResource TitleTextBlockStyle}" Text="Ver" />
                        <TextBlock Grid.Column="4" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Style="{StaticResource TitleTextBlockStyle}" Text="Product Owner" />
                        <TextBlock Grid.Column="5" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Style="{StaticResource TitleTextBlockStyle}" Text="Project Lead" />
                        <TextBlock Grid.Column="6" HorizontalAlignment="Center" FontSize="20" Foreground="#FFFFFF" Style="{StaticResource TitleTextBlockStyle}" Text="Scrum Master" />
                    </Grid>
                </ListView.Header>
            </ListView>
        </Grid>

        <Popup IsOpen="{Binding ShowUpdating, Mode=TwoWay}">
            <Grid Width="{Binding ActualWidth, ElementName=page}" Height="{Binding ActualHeight, ElementName=page}" Background="#99000000">
                <Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="#141A24" BorderBrush="White" BorderThickness="2" Padding="12,12,12,12">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" FontSize="36" FontWeight="Light" Text="updating... please wait..." />
                        <ProgressBar Grid.Row="1" IsIndeterminate="True" />
                    </Grid>
                </Border>
            </Grid>
        </Popup>

        <Popup IsOpen="{Binding PasswordPrompt, Mode=TwoWay}">
            <Grid Width="{Binding ActualWidth, ElementName=page}" Height="{Binding ActualHeight, ElementName=page}" Background="#99000000">
                <Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="#141A24" BorderBrush="White" BorderThickness="2" Padding="12,12,12,12">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Margin="0,0,0,12" FontSize="36" FontWeight="Light" Text="please provide your password to continue" />
                        <PasswordBox Grid.Row="1" Margin="0,0,0,12" Password="{Binding UserProvidedPassword, Mode=TwoWay}" />
                        <StackPanel Grid.Row="2" HorizontalAlignment="Right" Orientation="Horizontal">
                            <Button Margin="0,0,12,0" Command="{Binding GoToSettings}" Content="settings" />
                            <Button Command="{Binding PasswordProvided}" Content="okay" />
                        </StackPanel>
                    </Grid>
                </Border>
            </Grid>
        </Popup>

        <Popup IsOpen="{Binding ShowLegend, Mode=TwoWay}">
            <Grid Width="{Binding ActualWidth, ElementName=page}" Height="{Binding ActualHeight, ElementName=page}" Background="#99000000">
                <Border Width="374" Height="500" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#141A24" BorderBrush="White" BorderThickness="2">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Border Grid.Row="0" Background="#141A24" BorderBrush="White" BorderThickness="0,0,0,2">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="auto" />
                                </Grid.ColumnDefinitions>

                                <TextBlock Grid.Column="0" Margin="5" VerticalAlignment="Center" FontSize="25" FontWeight="Bold" Foreground="White" Text="Status Legend" />

                                <Button Grid.Column="1" HorizontalAlignment="Right" Command="{Binding CloseLegend}" Content="close" />
                            </Grid>
                        </Border>
                        <local:StatusLegend Grid.Row="1" Padding="12" />
                    </Grid>
                </Border>
            </Grid>
        </Popup>
    </Grid>
    <Page.BottomAppBar>
        <AppBar>
            <Grid>
                <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                    <AppBarButton Command="{Binding OpenLegend}" Icon="Directions" Label="Status Legend" />
                </StackPanel>

                <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                    <StackPanel.Resources>
                        <converters:BooleanToStringConverter x:Key="BooleanToStringConverter" FalseValue="Show ALL items" TrueValue="Switch to filtered view" />
                    </StackPanel.Resources>
                    <AppBarButton Command="{Binding ClearCache}" Icon="Clear" Label="Clear Cache" />
                    <AppBarButton Command="{Binding Refresh}" Icon="Refresh" Label="Refresh" />
                    <AppBarButton Command="{Binding ToggleHiddenItems}" Icon="Preview" Label="{Binding ShowAllItems, Converter={StaticResource BooleanToStringConverter}}" />
                    <AppBarButton Click="AppBarSaveButton_Click" Icon="Save" Label="Save Image" />
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>
</Page>